
# ======================================================================
# Project:    Closed borders, closed minds? COVID-related border closures,
#             EU support and hostility towards immigrants
#
# Script:     Data Preperation - Treatment Vairbales and Panel View
#
# Authors:    Lisa Herbig (l.j.herbig@uva.nl)
#             Asli Unan (a.unan@uva.nl)
#
# Date:       2025-03-24
# ======================================================================

# Description:
# This script prepares the previously generated dataset for the data analysis and generates the treatment variables

# ----------------------------------------------------------------------
# Load libraries
# ----------------------------------------------------------------------

library("did2s")
library("dplyr")
library("foreign")
library("ggplot2")
library("haven")
library("lmtest")
library("lubridate")
library("modelsummary")
library("PanelMatch")
library("panelView")
library("readr")       # Reading csv files ("1.3.1")
library("tidyr")
library("tidyverse")

## Read the files in
df_iso = readRDS("~/work/November_2024/R_out/FINAL_border_df_dist25.rds")

#Code NESW Region
df_iso$East=0
df_iso$East[df_iso$iso2.y==1]=1 #Austria
df_iso$East[df_iso$iso2.y==4]=1 # Czech Republic
df_iso$East[df_iso$iso2.y==10]=1 # Poland

df_iso$West=0
df_iso$West[df_iso$iso2.y==9]=1 # Netherlands
df_iso$West[df_iso$iso2.y==2]=1 # Belgium
df_iso$West[df_iso$iso2.y==8]=1 # Luxembourg
df_iso$West[df_iso$iso2.y==7]=1 # France

df_iso$South=0
df_iso$South[df_iso$iso2.y==3]=1 # Switzerland
df_iso$South[df_iso$iso2.y==1]=1 # Austria

df_iso$North=0
df_iso$North[df_iso$iso2.y==6]=1 # Denmark

df_iso$FR=0
df_iso$FR[df_iso$iso2.y==7]=1 # France

df_iso$BE=0
df_iso$BE[df_iso$iso2.y==2]=1 # Belgium

df_iso$AU=0
df_iso$AU[df_iso$iso2.y==1]=1 # Austria

df_iso$CZ=0
df_iso$CZ[df_iso$iso2.y==4]=1 # Czech

df_iso$PO=0
df_iso$PO[df_iso$iso2.y==10]=1 # Poland

df_iso$SW=0
df_iso$SW[df_iso$iso2.y==3]=1 # Switzerland

df_iso$DK=0
df_iso$DK[df_iso$iso2.y==6]=1 # Denmark

df_iso$NL=0
df_iso$NL[df_iso$iso2.y==2]=1 # Netherlands


df_iso$LUX=0
df_iso$LUX[df_iso$iso2.y==8]=1 # Luxembourg

##########
df_iso_work = df_iso %>%
  drop_na(iso2.y)

df_iso_work = df_iso %>%
  distinct(iso2.y, weekyear, .keep_all=TRUE)

df_iso_work$weekyear_f = factor(df_iso_work$weekyear)
df_iso_work$weekyear_i = as.integer(df_iso_work$weekyear_f)

df_iso_work$internal_closure_binary=NA
df_iso_work$internal_closure_binary[df_iso_work$internal_closure < 0.5]=0
df_iso_work$internal_closure_binary[df_iso_work$internal_closure >= 0.5]=1
table(df_iso_work$internal_closure_binary)

df_iso_work$external_closure_binary=NA
df_iso_work$external_closure_binary[df_iso_work$external_closure < 0.5]=0
df_iso_work$external_closure_binary[df_iso_work$external_closure >= 0.5]=1
table(df_iso_work$external_closure_binary)

df_iso_work$closure_both_binary=NA
df_iso_work$closure_both_binary[df_iso_work$closure_both < 0.5]=0
df_iso_work$closure_both_binary[df_iso_work$closure_both >= 0.5]=1
table(df_iso_work$closure_both_binary)

df_iso_work$quarantine_continuous_binary=NA
df_iso_work$quarantine_continuous_binary[df_iso_work$quarantine_continuous < 1]=0
df_iso_work$quarantine_continuous_binary[df_iso_work$quarantine_continuous >= 1]=1
table(df_iso_work$quarantine_continuous_binary)

df_iso_work$quarantine_until_june_binary=NA
df_iso_work$quarantine_until_june_binary[df_iso_work$quarantine_until_june < 0.5]=0
df_iso_work$quarantine_until_june_binary[df_iso_work$quarantine_until_june >= 0.5]=1
table(df_iso_work$quarantine_until_june_binary)

df_iso_work$risk_areas_binary=0
df_iso_work$risk_areas_binary[df_iso_work$risk_areas < 0.5]=0
df_iso_work$risk_areas_binary[df_iso_work$risk_areas >= 0.5]=1
table(df_iso_work$risk_areas_binary)

df_iso_work$internal_closure_binary = as.numeric(df_iso_work$internal_closure_binary)
df_iso_work$external_closure_binary = as.numeric(df_iso_work$external_closure_binary)
df_iso_work$closure_both_binary = as.numeric(df_iso_work$closure_both_binary)
df_iso_work$quarantine_continuous_binary = as.numeric(df_iso_work$quarantine_continuous_binary)
df_iso_work$quarantine_until_june_binary = as.numeric(df_iso_work$quarantine_until_june_binary)
df_iso_work$risk_areas_binary = as.numeric(df_iso_work$risk_areas_binary)

df_iso_work_dd = df_iso_work %>%
  select(internal_closure_binary, external_closure_binary, closure_both_binary, quarantine_continuous_binary, 
         quarantine_until_june_binary, risk_areas_binary, syear, con_germany, con_europe, satisf_democracy,
         weekyear, iso2.y, dist_extremes, dist_25, dist_50, border_region_25, border_region_50, working_abroad, university, EU_residence, 
         CDU_CSU,AfD, CDU_2018, AfD_2018, CSU_2018, SPD_2018, GRUNE_2018, LINKE_2018, NOELEGIBILITYVOTE_2018, NOVOTE_2018, NPD_REPUB_RECHTE_2018,
         FDP_2018,OTHER_PARTY_2018, HOMEOFFICE, CONTACTABROAD, Voting_2018_LeftRight, Voting_2018_GALTAN, kr_foreigner,
         kr_inz_rate, age, East, West, South, North, FR, BE,AU, CZ,PO,LUX,SW, DK, NL,female, changing_region, mode_phone, other_residence, second_citizen_cat, german_citizen_cat,
         translation, code_m18_030,refugee_risk_short, refugee_risk_long, worry_eco_dev,unemployed, 
         worry_eco_sit,worry_ret_prov,worry_health,worry_env_pro,worry_env_change,worry_peace,worry_crime,
         worry_soc_coh,worry_migration,worry_mig_host,worry_tech,worry_quali,	worry_wlb,worry_sec_work,refugee_eco,	
         refugee_culture,	refugee_ger_living,political_interest,pol_soc_engagement,risk_taking,doctor_3month_n_visits,no_doctor_3month,control_life, 
         run_down, well_balanced, worry_pca, immigration_pca, iso2_pop, var_rate_14_day_per_100k)

df_iso_work_dd$weekyear_i = match(df_iso_work_dd$weekyear, unique(df_iso_work_dd$weekyear))
df_iso_work_dd$weekyear_i = as.numeric(factor(df_iso_work_dd$weekyear_i))
df_iso_work_dd$weekyear_i = as.integer(as.factor(df_iso_work_dd$weekyear_i))
df_iso_work_dd$age = as.numeric(df_iso_work_dd$age)
df_iso_work_dd$female = as.numeric(df_iso_work_dd$female)
df_iso_work_dd$working_abroad = as.numeric(df_iso_work_dd$working_abroad)
df_iso_work_dd$university = as.numeric(df_iso_work_dd$university)
df_iso_work_dd$EU_residence = as.numeric(df_iso_work_dd$EU_residence)
df_iso_work_dd$german_citizen_cat = as.numeric(df_iso_work_dd$german_citizen_cat)
df_iso_work_dd$translation = as.numeric(df_iso_work_dd$translation)
df_iso_work_dd$second_citizen_cat = as.numeric(df_iso_work_dd$second_citizen_cat)
df_iso_work_dd$unemployed = as.numeric(df_iso_work_dd$unemployed)
df_iso_work_dd$kr_inz_rate = as.numeric(df_iso_work_dd$kr_inz_rate)
df_iso_work_dd$kr_foreigner = as.numeric(df_iso_work_dd$kr_foreigner)
df_iso_work_dd$iso2_pop = as.numeric(df_iso_work_dd$iso2_pop)
df_iso_work_dd$var_rate_14_day_per_100k = as.numeric(df_iso_work_dd$var_rate_14_day_per_100k)
df_iso_work_dd$Voting_2018_LeftRight = as.numeric(df_iso_work_dd$Voting_2018_LeftRight)
df_iso_work_dd$Voting_2018_GALTAN = as.numeric(df_iso_work_dd$Voting_2018_GALTAN)
df_iso_work_dd$CDU_CSU = as.numeric(df_iso_work_dd$CDU_CSU)
df_iso_work_dd$AfD = as.numeric(df_iso_work_dd$AfD)
df_iso_work_dd$CDU_2018 = as.numeric(df_iso_work_dd$CDU_2018)
df_iso_work_dd$CSU_2018 = as.numeric(df_iso_work_dd$CSU_2018)
df_iso_work_dd$SPD_2018 = as.numeric(df_iso_work_dd$SPD_2018)
df_iso_work_dd$GRUNE_2018 = as.numeric(df_iso_work_dd$GRUNE_2018)
df_iso_work_dd$LINKE_2018 = as.numeric(df_iso_work_dd$LINKE_2018)
df_iso_work_dd$AfD_2018 = as.numeric(df_iso_work_dd$AfD_2018)
df_iso_work_dd$FDP_2018 = as.numeric(df_iso_work_dd$FDP_2018)
df_iso_work_dd$NPD_REPUB_RECHTE_2018 = as.numeric(df_iso_work_dd$NPD_REPUB_RECHTE_2018)
df_iso_work_dd$NOELEGIBILITYVOTE_2018 = as.numeric(df_iso_work_dd$NOELEGIBILITYVOTE_2018)
df_iso_work_dd$NOVOTE_2018 = as.numeric(df_iso_work_dd$NOVOTE_2018)
df_iso_work_dd$OTHER_PARTY_2018 = as.numeric(df_iso_work_dd$OTHER_PARTY_2018)
df_iso_work_dd$HOMEOFFICE.x = as.numeric(df_iso_work_dd$HOMEOFFICE)
df_iso_work_dd$CONTACTABROAD = as.numeric(df_iso_work_dd$CONTACTABROAD)
df_iso_work_dd$changing_region = as.numeric(df_iso_work_dd$changing_region)
df_iso_work_dd$other_residence = as.numeric(df_iso_work_dd$other_residence)
df_iso_work_dd$mode_phone = as.numeric(df_iso_work_dd$mode_phone)
df_iso_work_dd$dist_25 = as.numeric(df_iso_work_dd$dist_25)
df_iso_work_dd$dist_50 = as.numeric(df_iso_work_dd$dist_50)
df_iso_work_dd$dist_extremes = as.numeric(df_iso_work_dd$dist_extremes)
df_iso_work_dd$border_region_25 = as.numeric(df_iso_work_dd$border_region_25)
df_iso_work_dd$border_region_50 = as.numeric(df_iso_work_dd$border_region_50)
df_iso_work_dd$con_germany = as.numeric(df_iso_work_dd$con_germany)
df_iso_work_dd$con_europe = as.numeric(df_iso_work_dd$con_europe)
df_iso_work_dd$satisf_democracy = as.numeric(df_iso_work_dd$satisf_democracy)
df_iso_work_dd$iso2.y_i = match(df_iso_work_dd$iso2.y, unique(df_iso_work_dd$iso2.y))
df_iso_work_dd$worry_migration = as.numeric(df_iso_work_dd$worry_migration)
df_iso_work_dd$refugee_risk_long = as.numeric(df_iso_work_dd$refugee_risk_long)
df_iso_work_dd$refugee_risk_short = as.numeric(df_iso_work_dd$refugee_risk_short)
df_iso_work_dd$worry_eco_dev = as.numeric(df_iso_work_dd$worry_eco_dev)
df_iso_work_dd$worry_eco_sit = as.numeric(df_iso_work_dd$worry_eco_sit)
df_iso_work_dd$worry_ret_prov = as.numeric(df_iso_work_dd$worry_ret_prov)
df_iso_work_dd$worry_health = as.numeric(df_iso_work_dd$worry_health)
df_iso_work_dd$worry_env_pro = as.numeric(df_iso_work_dd$worry_env_pro)
df_iso_work_dd$worry_env_change = as.numeric(df_iso_work_dd$worry_env_change)
df_iso_work_dd$worry_peace = as.numeric(df_iso_work_dd$worry_peace)
df_iso_work_dd$worry_crime = as.numeric(df_iso_work_dd$worry_crime)
df_iso_work_dd$worry_soc_coh = as.numeric(df_iso_work_dd$worry_soc_coh)
df_iso_work_dd$worry_mig_host = as.numeric(df_iso_work_dd$worry_mig_host)
df_iso_work_dd$worry_tech = as.numeric(df_iso_work_dd$worry_tech)
df_iso_work_dd$worry_quali = as.numeric(df_iso_work_dd$worry_quali)
df_iso_work_dd$worry_wlb = as.numeric(df_iso_work_dd$worry_wlb)
df_iso_work_dd$worry_sec_work = as.numeric(df_iso_work_dd$worry_sec_work)
df_iso_work_dd$worry_pca = as.numeric(df_iso_work_dd$worry_pca)
df_iso_work_dd$immigration_pca = as.numeric(df_iso_work_dd$immigration_pca)
df_iso_work_dd$refugee_eco = as.numeric(df_iso_work_dd$refugee_eco)
df_iso_work_dd$refugee_culture = as.numeric(df_iso_work_dd$refugee_culture)
df_iso_work_dd$refugee_ger_living = as.numeric(df_iso_work_dd$refugee_ger_living)
df_iso_work_dd$political_interest = as.numeric(df_iso_work_dd$political_interest)
df_iso_work_dd$pol_soc_engagement = as.numeric(df_iso_work_dd$pol_soc_engagement)
df_iso_work_dd$risk_taking = as.numeric(df_iso_work_dd$risk_taking)
df_iso_work_dd$no_doctor_3month = as.numeric(df_iso_work_dd$no_doctor_3month)
df_iso_work_dd$control_life = as.numeric(df_iso_work_dd$control_life)
df_iso_work_dd$run_down = as.numeric(df_iso_work_dd$run_down)
df_iso_work_dd$well_balanced = as.numeric(df_iso_work_dd$well_balanced)
df_iso_work_dd$lockdown=0
df_iso_work_dd$lockdown[df_iso_work_dd$code_m18_030==1 | df_iso_work_dd$code_m18_030==2|
                            df_iso_work_dd$code_m18_030==3]=1
df_iso_work_dd$lockdown = as.numeric(df_iso_work_dd$lockdown)
df_iso_work_dd$lockdown = as.numeric(as.factor(df_iso_work_dd$lockdown))
df_iso_work_dd$East = as.numeric(as.factor(df_iso_work_dd$East))
df_iso_work_dd$West = as.numeric(as.factor(df_iso_work_dd$West))
df_iso_work_dd$North = as.numeric(as.factor(df_iso_work_dd$North))
df_iso_work_dd$South = as.numeric(as.factor(df_iso_work_dd$South))
df_iso_work_dd$FR = as.numeric(as.factor(df_iso_work_dd$FR))
df_iso_work_dd$BE = as.numeric(as.factor(df_iso_work_dd$BE))
df_iso_work_dd$AU = as.numeric(as.factor(df_iso_work_dd$AU))
df_iso_work_dd$CZ = as.numeric(as.factor(df_iso_work_dd$CZ))
df_iso_work_dd$SW = as.numeric(as.factor(df_iso_work_dd$SW))
df_iso_work_dd$DK = as.numeric(as.factor(df_iso_work_dd$DK))
df_iso_work_dd$NL = as.numeric(as.factor(df_iso_work_dd$NL))
df_iso_work_dd$LUX = as.numeric(as.factor(df_iso_work_dd$LUX))

### Make ANY treatment var
df_iso_work_dd$any_closure_binary=NA
df_iso_work_dd$any_closure_binary[df_iso_work_dd$internal_closure_binary==1 | df_iso_work_dd$external_closure_binary==1]=1
df_iso_work_dd$any_closure_binary[df_iso_work_dd$internal_closure_binary==0 & df_iso_work_dd$external_closure_binary==0]=0
df_iso_work_dd$any_closure_binary = as.numeric(df_iso_work_dd$any_closure_binary)
table(df_iso_work_dd$any_closure_binary)

### Make ANY CLOSURE AND CONTINUOUS QUARANTINE treatment var
df_iso_work_dd$combined_binary=NA
df_iso_work_dd$combined_binary[df_iso_work_dd$any_closure_binary==1 | df_iso_work_dd$quarantine_continuous_binary==1]=1
df_iso_work_dd$combined_binary[df_iso_work_dd$any_closure_binary==0 & df_iso_work_dd$quarantine_continuous_binary==0]=0
df_iso_work_dd$combined_binary = as.numeric(df_iso_work_dd$combined_binary)

### Make ANY CLOSURE AND RISK AREA treatment var
df_iso_work_dd$smartcombined_binary=NA
df_iso_work_dd$smartcombined_binary[df_iso_work_dd$any_closure_binary==1 | df_iso_work_dd$risk_areas_binary==1]=1
df_iso_work_dd$smartcombined_binary[df_iso_work_dd$any_closure_binary==0 & df_iso_work_dd$risk_areas_binary==0]=0
df_iso_work_dd$smartcombined_binary = as.numeric(df_iso_work_dd$smartcombined_binary)

### Assign 0s for Control Group
df_iso_work_dd$internal_closure_binary_control0=NA
df_iso_work_dd$internal_closure_binary_control0[df_iso_work_dd$iso2.y==5]=0
df_iso_work_dd$internal_closure_binary_control0[df_iso_work_dd$internal_closure_binary < 0.5]=0
df_iso_work_dd$internal_closure_binary_control0[df_iso_work_dd$internal_closure_binary >= 0.5]=1
table(df_iso_work_dd$internal_closure_binary)
table(df_iso_work_dd$internal_closure_binary_control0)

df_iso_work_dd$external_closure_binary_control0 = NA
df_iso_work_dd$external_closure_binary_control0[df_iso_work_dd$iso2.y==5]=0
df_iso_work_dd$external_closure_binary_control0[df_iso_work_dd$external_closure_binary < 0.5]=0
df_iso_work_dd$external_closure_binary_control0[df_iso_work_dd$external_closure_binary >= 0.5]=1
table(df_iso_work_dd$external_closure_binary)
table(df_iso_work_dd$external_closure_binary_control0)

df_iso_work_dd$any_closure_binary_control0 = NA
df_iso_work_dd$any_closure_binary_control0[df_iso_work_dd$iso2.y==5]=0
df_iso_work_dd$any_closure_binary_control0[df_iso_work_dd$internal_closure_binary==1 | df_iso_work_dd$external_closure_binary==1]=1
df_iso_work_dd$any_closure_binary_control0[df_iso_work_dd$internal_closure_binary==0 & df_iso_work_dd$external_closure_binary==0]=0
table(df_iso_work_dd$any_closure_binary)
table(df_iso_work_dd$any_closure_binary_control0)

############################################################

df_iso_work_dd$combined_binary_control0[df_iso_work_dd$iso2.y==5]=0
df_iso_work_dd$combined_binary_control0[df_iso_work_dd$any_closure_binary==1 | df_iso_work_dd$quarantine_continuous_binary==1]=1
df_iso_work_dd$combined_binary_control0[df_iso_work_dd$any_closure_binary==0 & df_iso_work_dd$quarantine_continuous_binary==0]=0
table(df_iso_work_dd$combined_binary)
table(df_iso_work_dd$combined_binary_control0)

df_iso_work_dd$smartcombined_binary_control0 = NA
df_iso_work_dd$smartcombined_binary_control0[df_iso_work_dd$iso2.y==5]=0
df_iso_work_dd$smartcombined_binary_control0[df_iso_work_dd$any_closure_binary==1 | df_iso_work_dd$risk_areas_binary==1]=1
df_iso_work_dd$smartcombined_binary_control0[df_iso_work_dd$any_closure_binary==0 & df_iso_work_dd$risk_areas_binary==0]=0
table(df_iso_work_dd$smartcombined_binary)
table(df_iso_work_dd$smartcombined_binary_control0)

df_iso_work_dd$closure_both_binary_control0 = NA
df_iso_work_dd$closure_both_binary_control0[df_iso_work_dd$iso2.y==5]=0
df_iso_work_dd$closure_both_binary_control0[df_iso_work_dd$closure_both_binary < 0.5]=0
df_iso_work_dd$closure_both_binary_control0[df_iso_work_dd$closure_both_binary >= 0.5]=1
table(df_iso_work_dd$closure_both_binary)
table(df_iso_work_dd$closure_both_binary_control0)

df_iso_work_dd$quarantine_continuous_binary_control0 = NA
df_iso_work_dd$quarantine_continuous_binary_control0[df_iso_work_dd$iso2.y==5]=0
df_iso_work_dd$quarantine_continuous_binary_control0[df_iso_work_dd$quarantine_continuous_binary < 1]=0
df_iso_work_dd$quarantine_continuous_binary_control0[df_iso_work_dd$quarantine_continuous_binary >= 1]=1
table(df_iso_work_dd$quarantine_continuous_binary)
table(df_iso_work_dd$quarantine_continuous_binary_control0)

##NORMALIZE VARIABLES AND ADJUST SUMS TO POPULATION SIZE

#df_iso_work_dd$East_n = normalize(df_iso_work_dd$East)# don#t normalize EAST because it is binary
df_iso_work_dd$working_abroad_pn = (df_iso_work_dd$working_abroad / df_iso_work_dd$iso2_pop) * 100000
df_iso_work_dd$kr_foreigner_pn = (df_iso_work_dd$kr_foreigner / df_iso_work_dd$iso2_pop) * 100000
df_iso_work_dd$CONTACTABROAD_pn = (df_iso_work_dd$CONTACTABROAD / df_iso_work_dd$iso2_pop) * 100000
df_iso_work_dd$HOMEOFFICE_pn = (df_iso_work_dd$HOMEOFFICE / df_iso_work_dd$iso2_pop) * 100000
df_iso_work_dd$mode_phone_pn = (df_iso_work_dd$mode_phone / df_iso_work_dd$iso2_pop) * 100000
df_iso_work_dd$unemployed_pn = (df_iso_work_dd$unemployed / df_iso_work_dd$iso2_pop) * 100000
df_iso_work_dd$university_pn = (df_iso_work_dd$university / df_iso_work_dd$iso2_pop) * 100000
df_iso_work_dd$EU_residence_pn = (df_iso_work_dd$EU_residence / df_iso_work_dd$iso2_pop) * 100000
df_iso_work_dd$Voting_2018_LeftRight_pn = (df_iso_work_dd$Voting_2018_LeftRight / df_iso_work_dd$iso2_pop) * 100000
df_iso_work_dd$female_pn = (df_iso_work_dd$female / df_iso_work_dd$iso2_pop) * 100000
df_iso_work_dd$AfD_pn = (df_iso_work_dd$AfD / df_iso_work_dd$iso2_pop) * 100000

normalize = function(x) {
  data_range = max(x, na.rm = TRUE) - min(x, na.rm = TRUE)
  return((x - min(x, na.rm = TRUE)) / data_range)
}

df_iso_work_dd$East_n = normalize(df_iso_work_dd$East)
df_iso_work_dd$working_abroad_n = normalize(df_iso_work_dd$working_abroad_pn)
df_iso_work_dd$kr_foreigner_n = normalize(df_iso_work_dd$kr_foreigner_pn)
df_iso_work_dd$CONTACTABROAD_n = normalize(df_iso_work_dd$CONTACTABROAD_pn)
df_iso_work_dd$HOMEOFFICE_n = normalize(df_iso_work_dd$HOMEOFFICE_pn)
df_iso_work_dd$mode_phone_n = normalize(df_iso_work_dd$mode_phone_pn)
df_iso_work_dd$iso2_pop_n = normalize(df_iso_work_dd$iso2_pop)
df_iso_work_dd$age_n = normalize(df_iso_work_dd$age)
df_iso_work_dd$female_n = normalize(df_iso_work_dd$female_pn)
df_iso_work_dd$unemployed_n = normalize(df_iso_work_dd$unemployed_pn)
df_iso_work_dd$university_n = normalize(df_iso_work_dd$university_pn)
df_iso_work_dd$EU_residence_n = normalize(df_iso_work_dd$EU_residence_pn)
df_iso_work_dd$Voting_2018_LeftRight_n = normalize(df_iso_work_dd$Voting_2018_LeftRight_pn)
df_iso_work_dd$kr_inz_rate_n = normalize(df_iso_work_dd$kr_inz_rate)
df_iso_work_dd$con_europe_n = normalize(df_iso_work_dd$con_europe)
df_iso_work_dd$AfD_n = normalize(df_iso_work_dd$AfD_pn)
df_iso_work_dd$immigration_pca_n = normalize(df_iso_work_dd$immigration_pca)*(-1)
df_iso_work_dd$refugee_eco_n = normalize(df_iso_work_dd$refugee_eco)
df_iso_work_dd$refugee_culture_n = normalize(df_iso_work_dd$refugee_culture)
df_iso_work_dd$refugee_ger_living_n = normalize(df_iso_work_dd$refugee_ger_living)

saveRDS(df_iso_work_dd,"~/work/November_2024/R_out/df_iso_work_dd_25.rds")